<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/login.css">
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //尝试获取email
            var email = sessionStorage.getItem("email");
            if (email) {
                $("#loginForm input[name='email']").val(email);
                sessionStorage.removeItem("email");
            }

           $("#loginForm").ajaxForm(function (data) {
               if (data.success) {
                   //缓存登录成功的用户,用于数据回显
                   //sessionStorage:在同一个标签页中共享数据
                   //把返回的JSON对象转成字符串,存入sessionStorage
                   var user = JSON.stringify(data.data);
                   sessionStorage.setItem("user", user);

                   //登录成功,刷新主页
                   //当前登录界面是另一个界面中作为了子界面,应该让主界面做刷新
                   parent.location.href = "/index.html";
               } else {
                   //登录失败
                   $(document).dialog({
                       titleShow: false,
                       style: "IOS",
                       content: data.msg,
                       autoClose: 1500
                   });
               }
           });
        });
    </script>
</head>
<body>
<div class="container">
    <h5>登录</h5>

    <div class="card card-container ">
        <i id="profile-img" class="fa fa-user-circle fa-5x profile-img"></i>
        <form class="form-signin" id="loginForm" action="/sessions" method="post">
            <input type="email" name="email" value="bunny@wolfcode.cn" class="form-control badge-pill" placeholder="邮箱">
            <input type="password" name="password" value="1" class="form-control badge-pill" placeholder="密码">
            <a href="#" class="forgot-password">
                忘记密码？
            </a>
            <button class="btn btn-lg badge-pill" type="submit">登录</button>
        </form>
    </div>


    <a href="/register.html" class="registerLink">
        新用户？点击这里登录
    </a>
</div>

</body>
</html>
